package com.leetcode.algorithm.y22.m05;

/**
 * 70. 爬楼梯 
 * https://leetcode.cn/problems/climbing-stairs/
 * 
 * @author jie.deng
 *
 */
class Question0070Solution01 {

	// DP
	/**
	 * 1 <= n <= 45
	 * 
	 * @param n
	 * @return
	 */
	public int climbStairs(int n) {
		if (n <= 1) {
			return n;
		}
		// dp一维数组
		int[] dp = new int[n + 1];

		// 初始状态
		dp[0] = 1;// WARNING:这里不是0而是1
		dp[1] = 1;

		for (int i = 2; i <= n; i++) {
			// 状态转移方程
			dp[i] = dp[i - 1] + dp[i - 2];
		}

		return dp[n];
	}

}